import re
text="apple apple apple apple"
pattern=r'apple'
replacement ="orange"

new_text=re.sub(pattern,replacement,text,count=2)
print(new_text)